const app = getApp();
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    Custom: app.globalData.Custom,
    bottom: 100,
    bgColor2: "#5677fc",
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    neirong: null,
    userInfo: null,
    queryParam: {
      pageIndex: "1",
      pageSize: "100"
    },
    showLogin: false,
    spinShow: false,
    mode: 'circle', // circle 圆形 square 方形
    bottom: 100, //距离顶部距离 rpx
    top: 50, //距离顶部多少距离显示 px
    bgColor: 'blue', //背景色
    color: '#fff', //文字图标颜色
    color1: '#9a9a9a', //文字图标颜色
    icon: 'triangleupfill', //图标
    right: '24', //距离右侧距离 rpx
    scrollTop: 0,
    userInfo: [],
    shuLiang: null,
    showLogin1:false,
    bgColor1:'#f37b1d',
    //返回的学习视频数据
    videData:null,
    //视频数据的url
    videoUrl:null,
    color1:'#39b54a',
    swiperList: [{
      id: 0,
      type: 'image',
      url: '/images/安全中心1.jpg'
    },
    {
      id: 1,
      type: 'image',
      url: '../image/安全中心4.jpg'
    },
  ],
    categories: [
    ],
    cardCur: 0,
    curriculum: [{}],
    projectList: []
  },

//点击标题相当于查看按钮
  look(e){
  var trainPlanId = e.currentTarget.dataset.id;
  var token = wx.getStorageSync('token');
  wx.request({
    url: 'http://60.216.100.50:9006/ruoyi-api/train/learningGarden/courseware',
    method:"GET",
    header: {
      'Authorization': 'Bearer ' + token, // 在请求头中携带 token
      },
      data:{
      trainPlanId:trainPlanId
      },
      success: (res) => {
        var data = res.data.data;
        wx.navigateTo({
          url: '/packageG/studyInformation/studyInformation?data=' +encodeURIComponent(JSON.stringify(data)) 
        });
      },
      fail: (err) => {
        // 处理请求失败
        console.error(err);
      }
  })
  },

  cardSwiper: function cardSwiper(e) {
    this.setData({
      cardCur:e.detail.current
    })
  },
  //页面滚动执行方式
  onPageScroll(e) {
    this.setData({
      scrollTop: e.scrollTop
    })
  },
  gotoVideo(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageG/shipin/shipin?id=' + id,
    });
  },

//跳转到直播界面
  tomore() {
    wx.navigateTo({
      url: '/packageG/cart2/cart',
    });
  },

  gotoStudy(e) {
    let id = e.currentTarget.dataset.mid;
    if (id == "1") {
      wx.navigateTo({
        url: '/packageG/book/book',
      });
    }
    if (id == "2") {
      wx.navigateTo({
        url: '/packageG/project/project',
      });
    }
    if (id == "3") {
      wx.navigateTo({
        url: '/packageG/cert/cert',
      });
    }
    if (id == "4") {
      wx.navigateTo({
        url: '/packageG/wenDa/wenDa',
      });
    }
    if (id == "5") {
      wx.navigateTo({
        url: '/packageG/demo/demo',
      });
    }
    if (id == "6") {
      wx.navigateTo({
        url: '/packageG/toubiao/toubiao',
      });
    }
    if (id == "7") {
      wx.navigateTo({
        url: '/packageG/friend/friend',
      });
    }
    if (id == "8") {
      wx.navigateTo({
        url: '/packageG/standard/standard',
      });
    }
      if (id == "9") {
        wx.navigateTo({
        url: '/packageG/anli/anli',
      });
      }
      if (id == "10") {
        wx.navigateTo({
          url: '/packageG/wuliao/wuliao',
        });
      }
      if (id == "11") {
        wx.navigateTo({
          url: '/packageG/qualification/qualification',
        });
      }
      if (id == "12") {
        wx.navigateTo({
          url: '/packageG/daping/daping',
        });
      }
  },

  //页面初始化
  onLoad(e) {
    var token =  wx.getStorageSync('token');
    wx.request({
      url: 'http://60.216.100.50:9006/ruoyi-api/train/learningGarden/knowledgeList?pageNum=1&pageSize=10&trainName=&trainLecturerNickName=&trainBeginTime=&trainEndTime=',
      method:"GET",
      header: {
        'Authorization': 'Bearer ' + token, // 在请求头中携带 token
        },
      success: (res)=> {
        var data=res.data;
        this.setData({
          videData:data.rows
        })
        console.log(this.data.videData)
      },
      fail: function(err) {
        // 处理请求失败
        console.error(err);
      }
    })
  },

  jiandao(e) {
    const category = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageG/cart1/cart?category=' + category,
    })
  },
  mengxin(e){
    wx.navigateTo({
      url: '/packageG/mengxin/home',
    })
  },
  feature() {
    this.setData({
      showLogin: true
    })
  },
  navActivity(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../process1/process?id=' + id,
    });
  },
  onPullDownRefresh() {
    this.setData({
      spinShow: true
    });
    if (!this.loading) {
      this.search()
      wx.showToast({
        title: '刷新成功',
        icon: "none"
      })
    }
  },
  search: function () {
    app.formPost('/api/wx/student/video/pageList', this.data.queryParam)
      .then(res => {
        if (res.code == 1) {
          this.setData({
            curriculum: res.response.list,
            spinShow: false
          })
        } else {
          wx.showModal({
            title: res.message
          })
        }
      }).catch(e => {
        wx.showModal({
          title: e
        })
      })
  }
});